//
//  ZZStatus.swift
//  SinaWeibo
//
//  Created by QUAN on 15/11/16.
//  Copyright © 2015年 QUAN. All rights reserved.
//

import UIKit

class ZZStatus: NSObject {
    //微博微博创建时间
    var created_at : String?
    //微博ID
    var id : Int = 0
    //微博信息内容
    var text : String?
    //微博来源
    var source: String?
    //用户信息
    var user : ZZUser?
    //配图视图数组
    var pic_urls: [[String : String]]?
    
    //计算型属性
    var imageURLs: [NSURL]? {

        guard let urls = pic_urls else {
            return nil
        }
        
        var tempArray = [NSURL]()
        
        for item in urls {
            let url = NSURL(string: item["thumbnail_pic"]!)
            tempArray.append(url!)
        }
        return tempArray
    }
    
    //转发微博的内容
    var retweeted_status : ZZStatus?
    
    
    init(dict: [String : AnyObject]) {
        
        super.init()
        
        self.setValuesForKeysWithDictionary(dict)
        
    }
    override func setValue(value: AnyObject?, forKey key: String) {
        //把用户信息字典转模型
        if key == "user" {
            if let dict = value as? [String : AnyObject] {
                user = ZZUser(dict:dict)
            }
            return
        }
        //把转发微博的内容字典转模型
        if key == "retweeted_status" {
            if let dict = value as? [String : AnyObject] {
                self.retweeted_status = ZZStatus(dict: dict)
            }
            return
        }
        super.setValue(value, forKey: key)
    }
    
    //过滤掉没用的字段
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }
}



